
// export const baseURL = "https://mlpay.aoe1.top"//正式环境请求地址
export const baseURL = "https://yt9.natapp4.cc"//本地环境请求地址
export function req(method,url, param,responseType) {
	let sessionKey = uni.getStorageSync('sessionKey')
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseURL + url,
            method: method,
            data: param,
            header: {
            	'content-type': 'application/json;charset=UTF-8',
            	'X-HXCharge-Authentication': '' + sessionKey
            },
			responseType: responseType || '',
            success(res) {
                const { statusCode } = res
                switch (statusCode) {
                    case 200:
                        resolve(res)
                        break
                    case 404:
                        uni.showToast({
                            title: "暂未开放",
							icon:"none"
                        })
                        reject(res)
                        break;
                    case 401:
                        uni.clearStorageSync();
						let msg = res.data.message.toString().indexOf('please login first') > 0 ? '登录超时' : res.data.message.toString()
						uni.showToast({
							title: msg,
							icon: 'none'
						})
						
						setTimeout(()=> {
							uni.reLaunch({
								url: "/pages/login/login"
							})
						}, 500)
                        reject(res)
                        break;
					case 400:
						uni.showToast({
						    title: res.data.message,
							icon:"none"
						})
						reject(res)
						break;
                    default:;
                }
            },
            fail(err) {
                reject(err)
            }
        })
    })
}


